/*
Philip Dilse
dilsep
Assignment 3

unit test for updateCoins()
*/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include "dominion.h"
#include "dominion_helpers.h"

int main() {
    int i, j;
    int randomNum;
    int numPlayers = 4;
    int maxBonus = 10;
    int maxHand = 50;
    int handCount, bonus, expectedCoins;
    int k[10] = {adventurer, council_room, feast, gardens, mine, remodel,
                 smithy, village, baron, great_hall};
    struct gameState *gs = newGame();
    gs->numPlayers = numPlayers;
 
    // set up random number gen
    srand(time(NULL));

    for (handCount = 0; handCount <= maxHand; handCount++) {

        // set handCount for each player
        for (i = 0; i < numPlayers; i++) {
            gs->handCount[i] = handCount;
        }

        for (bonus = 0; bonus <= maxBonus; bonus++) {         

            // randomly assign cards to each players hand and compare expected
            // to value in state after updateCoins()
            for (i = 0; i < numPlayers; i++) {
                expectedCoins = 0;
                for (j = 0; j < handCount; j++) {
                    randomNum = rand() % 4;
                    if (randomNum == 0) { // random kingdom card, no coin value
                        gs->hand[i][j] = k[rand() % 10]; 
                    }
                    else if (randomNum == 1) {
                        gs->hand[i][j] = copper;
                        expectedCoins += 1;
                    }
                    else if (randomNum == 2) {
                        gs->hand[i][j] = silver;
                        expectedCoins += 2;
                    }
                    else {
                        gs->hand[i][j] = gold;                  
                        expectedCoins += 3;
                    }
                }
                expectedCoins += bonus;
                updateCoins(i, gs, bonus);

                if (expectedCoins != gs->coins) {
                    printf("updateCoins() error: handCount=%d bonus=%d expected=%d calculated=%d\n",
                            handCount, bonus, expectedCoins, gs->coins);
                }
            }
        }
    }
    free(gs);
    return 0;
}
